<?php
/**
 * Created by PhpStorm.
 * User: DaibiDaddy
 * Date: 2016/6/3
 * Time: 14:59
 */

namespace XiaoZhuBundle\Helper;


class MyForms{

    protected  $EM;

    public function __construct($em)
    {
        $this->EM = $em;
    }

    public function getClasses($className , $nameFeildName)
    {
        $rep = $this->EM->getRepository("AdminsBundle:$className");
        $allClasses = $rep->findAll();
        $classes = array();
        foreach ($allClasses as $class) {
            $func = "get$nameFeildName";
            $classes[$class->getId()] = $class->$func();
        }
        return $classes;
    }

    public function FoodClass()
    {

        /*name*/
        $name = array(
            "label"     =>"分类名称",
            "showType"  =>"text",
            "dataType"  =>"*2-200",
            "option"    => array()
        );

        /*orders*/
        $orders = array(
            "label"     =>"显示排序",
            "showType"  =>"text",
            "dataType"  =>"*",
            "option"    => array()
        );

        return array(
            "name"   => $name,
            "orders"   => $orders,
        );
    }

    public function Product()
    {
        /*Cid*/
        $options["cid"]["other"] = array(
            "choices"   => $this->getClasses("FoodClass","Name"),
        );
        $config["cid"] = array(
            "label"     =>"分类",
            "showType"  =>"select",
            "dataType"  =>"*",
            "option"    => $options["cid"]
        );

        $config["no"] = array(
            "label"     =>"产品编号",
            "showType"  =>"text",
            "dataType"  =>"*",
            "option"    => array()
        );

        $config["name"] = array(
            "label"     =>"产品名称",
            "showType"  =>"text",
            "dataType"  =>"*1-50",
            "option"    => array()
        );

        $config["marketPrice"] = array(
            "label"     =>"市场价格",
            "showType"  =>"text",
            "dataType"  =>"*",
            "option"    => array()
        );

        $config["price"] = array(
            "label"     =>"销售价格",
            "showType"  =>"text",
            "dataType"  =>"*",
            "option"    => array()
        );

        $config["stockPrice"] = array(
            "label"     =>"进货价格",
            "showType"  =>"text",
            "dataType"  =>"*",
            "option"    => array()
        );

        $config["num"] = array(
            "label"     =>"现有库存",
            "showType"  =>"text",
            "dataType"  =>"n",
            "option"    => array()
        );

        $config["searchInfo"] = array(
            "label"     =>"检索信息",
            "showType"  =>"text",
            "dataType"  =>"*",
            "option"    => array()
        );

        return $config;
    }



    public function ProductProduce()
    {

        $config["company"] = array(
            "label"     =>"生产厂家",
            "showType"  =>"text",
            "dataType"  =>"*",
            "option"    => array()
        );

        $config["address"] = array(
            "label"     =>"生产地址",
            "showType"  =>"text",
            "dataType"  =>"*",
            "option"    => array()
        );

        $config["time"] = array(
            "label"     =>"生产日期",
            "showType"  =>"date",
            "dataType"  =>"*",
            "option"    => array()
        );

        return $config;
    }

    public function ProductShow()
    {

        $config["title"] = array(
            "label"     =>"显示标题",
            "showType"  =>"text",
            "dataType"  =>"*",
            "option"    => array()
        );

        $config["cover"] = array(
            "label"     =>"封面图片",
            "showType"  =>"pic",
            "dataType"  =>"*",
            "option"    => array()
        );

        $config["img1"] = array(
            "label"     =>"橱窗图一",
            "showType"  =>"pic",
            "dataType"  =>"*",
            "option"    => array()
        );

        $config["img2"] = array(
            "label"     =>"橱窗图二",
            "showType"  =>"pic",
            "dataType"  =>"*",
            "option"    => array()
        );

        $config["img3"] = array(
            "label"     =>"橱窗图三",
            "showType"  =>"pic",
            "dataType"  =>"*",
            "option"    => array()
        );

        $config["intro"] = array(
            "label"     =>"图文介绍",
            "showType"  =>"pics",
            "dataType"  =>"",
            "option"    => array()
        );

        return $config;
    }

}